/**
 * @Date 2025/2/26 15:09
 * @Created by 衡盛永
 */

package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜品管理
 */
@RestController
@RequestMapping("/admin/dish")
@Api(tags = "菜品相关接口")
@Slf4j
public class DishController {

    @Autowired
    private DishService dishService;

    /**
     * 分页查询
     * @param dishPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> page(DishPageQueryDTO dishPageQueryDTO) {
        PageResult pageResult = dishService.pageQuery(dishPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 添加菜品
     * @param dishDTO
     * @return
     */
    @PostMapping("")
    @ApiOperation("添加菜品")
    public Result<List<Dish>> addDish(@RequestBody DishDTO dishDTO) {
        dishService.addDish(dishDTO);
        return Result.success();
    }

    /**
     * 某一菜品分类的菜品列表
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("某一菜品分类的菜品列表")
    public Result<List<Dish>> list(Integer categoryId) {
        List<Dish> list = dishService.list(categoryId);
        return Result.success(list);
    }
}
